package com.ztc.ZtcClassesSite.dao;
import java.text.SimpleDateFormat;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.aqgj.util.BaseDaoImpl;
import com.ztc.ZtcClassesSite.bean.ZtcClassesSite;
import com.ztc.ZtcClassesSite.dao.ZtcClassesSiteDao;

/**
 * <p>
 *
 * </p>
 *
 * @ClassName ZtcClassesSiteDao
 * @JDK 1.5
 * @author
 * @date
 */
@Repository("ZtcClassesSiteDao")
public class ZtcClassesSiteDao extends BaseDaoImpl<ZtcClassesSite> {
	private static final SimpleDateFormat DATE_TIME_FORMET = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	public String save(ZtcClassesSite ztcSite) {
		this.getHibernateTemplate().save(ztcSite);
		return ztcSite.getId();
	}

	public List<ZtcClassesSite> getAllZtcClassesSites() {
		return this.getAll();
	}

	public String delete(String id, String ztcClassesId,String modifyUserId) {
		String sql = "delete from ztc_classes_site where 1=1";
		if (id != null) {
			sql += " and id='" + id + "'";
		}
		if (ztcClassesId != null) {
			sql += " and fk_ztc_classes_id='" + ztcClassesId + "'";
		}
		if(modifyUserId!=null){
			sql += " and fk_modify_user_id='" + modifyUserId + "'";
		}
		if (this.currentSession().createNativeQuery(sql).executeUpdate() >= 0) {
			return "1";
		}
		return "0";
	}

	public List<ZtcClassesSite> searchInfoEquals(ZtcClassesSite ztcSite) {
		String sql = "select * from ztc_classes_site where 1=1";
		if (ztcSite.getName() != null) {
			sql += " and name='" + ztcSite.getName() + "'";
		}
		if (ztcSite.getAreaCity() != null) {
			sql += " and area_city='" + ztcSite.getAreaCity() + "'";
		}
		if (ztcSite.getAreaCode() != null) {
			sql += " and area_code='" + ztcSite.getAreaCode() + "'";
		}
		if (ztcSite.getManagerPhone()!= null) {
			sql += " and manager_phone='" + ztcSite.getManagerPhone() + "'";
		}
		if (ztcSite.getSequence() != null) {
			sql += " and sequence='" + ztcSite.getSequence() + "'";
		}
		if (ztcSite.getLat() != null) {
			sql += " and lat='" + ztcSite.getLat()+ "'";
		}
		if (ztcSite.getDepartureTime() != null) {
			sql += " and departure_time='" + DATE_TIME_FORMET.format(ztcSite.getDepartureTime()) + "'";
		}
		
		if (ztcSite.getFkZtcClassesId() != null) {
			sql += " and fk_ztc_classes_id='" + ztcSite.getFkZtcClassesId() + "'";
		}
		if (ztcSite.getId() != null) {
			sql += " and id='" + ztcSite.getId() + "'";
		}
		List<ZtcClassesSite> list = this.currentSession().createNativeQuery(sql,ZtcClassesSite.class).getResultList();
		return list;
	}
	

	public List<ZtcClassesSite> searchInfoLikes(String name, String areaCity,String managerPhone) {
		String sql = "select * from ztc_classes_site where 1=1";
		if (name != null) {
			sql += " and name like '%" + name + "%'";
		}
		if (managerPhone != null) {
			sql += " and manager_phone like '%" + managerPhone + "%'";
		}
		if (areaCity != null) {
			sql += " and area_city like '%" + areaCity + "%'";
		}
		List<ZtcClassesSite> list = this.currentSession().createNativeQuery(sql,ZtcClassesSite.class).getResultList();
		return list;
	}

	public String update(ZtcClassesSite ztcSite) {
		this.getHibernateTemplate().saveOrUpdate(ztcSite);
		if (ztcSite.getId() != null) {
			return "1";
		}
		return "0";
	}
}